{include file="index/header" /}
<body>
<form method="post" action="" id="listform">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
    <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <li> <a class="button border-main icon-plus-square-o" href="{:url('add')}"> 添加内容</a> </li>
        <li>搜索：</li>
          <li>
            <select name="nav_id" class="input" style="width:200px; line-height:17px;" onchange="changeNav()"  id="nav">
              <option value="0">请选择阶段</option>
              {foreach name='nav_data' item='nav'}
              <option value="{$nav.nav_id}" <?php if($nav['nav_id'] == $nav_id){echo 'selected';}?>>{$nav.nav_name}</option>
              {/foreach}
            </select>
          </li>
          <li>
            <select name="type_id" class="input" style="width:200px; line-height:17px;" onchange="changesearch()" id="type">
              <option value="0">请选择分类</option>
              {foreach name='type_data' item='type'}
              <option value="{$type.type_id}"  <?php if($type['type_id'] == $type_id){echo 'selected';}?>>{$type.type_name}</option>
              {/foreach}
            </select>
          </li>
          <li>
            <select name="s_id" class="input" style="width:200px; line-height:17px;" onchange="changesearch()">
              <option value="0">请选择章节</option>
              {foreach name='s_data' item='s'}
              <option value="{$s.s_id}"  <?php if($s['s_id'] == $s_id){echo 'selected';}?>>{$s.s_name}</option>
              {/foreach}
            </select>
          </li>
        <li>
          <input type="text" placeholder="请输入搜索关键字" name="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" value="{$keywords}" />
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a></li>
      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
        <th width="100" style="text-align:left; padding-left:20px;">ID</th>
        <th>排序</th>
        <th>名称</th>
        <th>发布人</th>
        <th>阶段名称</th>
        <th>分类名称</th>
        <th>章节名称</th>
        <th width="310">操作</th>
      </tr>
      {foreach name='data' item='v'}
        <tr>
          <td style="text-align:left; padding-left:20px;"><input type="checkbox" name="t_id[]" value="{$v.t_id}" />
           {$v.t_id}</td>
           <td><input type="text" name="t_sort[{$v.t_id}]" value="{$v.t_sort}" style="width:50px; text-align:center; border:1px solid #ddd; padding:7px 0;" /></td>
          <td width="10%">{$v.t_name}</td>
          <td width="10%">{$v.admin_name}</td>
          <td>{$v.nav_name}</td>
          <td><font color="#00CC99">{$v.type_name}</font></td>
          <td><font color="#00CC99">{$v.s_name}</font></td>
          <td><div class="button-group"> <a class="button border-main" href="{:url('edit',['t_id' => $v['t_id']])}"><span class="icon-edit"></span> 修改</a> <a class="button border-red" href="{:url('delete',['t_id' => $v['t_id']])}"  onclick="if(confirm('确定删除?')==false)return false;"><span class="icon-trash-o"></span> 删除</a> </div></td>
        </tr>
        {/foreach}
      <tr>
        <td style="text-align:left; padding:19px 0;padding-left:20px;"><input type="checkbox" id="checkall"/>
          全选 </td>
        <td colspan="8" style="text-align:left;padding-left:20px;"><a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" onclick="DelSelect()"> 删除</a> <a href="javascript:void(0)" style="padding:5px 15px; margin:0 10px;" class="button border-blue icon-edit" onclick="sorts()"> 排序</a> 
          复制：
          <select style="padding:5px 15px; border:1px solid #ddd;"  class="navCopy">
            <option value="0">请选择课程</option>
            {foreach name='nav_data' item='nav'}
            <option value="{$nav.nav_id}">{$nav.nav_name}</option>
            {/foreach}
          </select>
          <select  style="padding:5px 15px; border:1px solid #ddd;" class="typeCopy">
            <option value="0">请选择阶段</option>
          </select>
          <select  style="padding:5px 15px; border:1px solid #ddd;" name="sCopyId" onchange="changecate(this)" class="sCopy">
            <option value="0">请选择章节</option>
          </select>
      </td>
      </tr>
      <tr>
        <td colspan="8">{$data->render()}</td>
      </tr>
    </table>
  </div>
  <input type="hidden" name="status" value="">
</form>

<script type="text/javascript">
$('.navCopy').change(function(){
  var nav_id = $(this).val();
  $(".type option:gt(0)").remove();
  $(".sCopy option:gt(0)").remove();
  if(nav_id == ''){
    return;
  }
  $.ajax({
    type:'GET',
    url :"{:url('course/getType')}",
    data:'nav_id='+nav_id,
    dataType:'json',
    success : function(data){
      $.each(data.type_data, function(k,v){
        $('.typeCopy').append('<option value="'+v.type_id+'">'+v.type_name+'</option>');
      });
      $('input[name=course_sort]').val(data.sort);
    }
  });
});
$('.typeCopy').change(function(){
    var type_id = $(this).val();
    $(".sCopy option:gt(0)").remove();
    if(type_id == ''){
      return;
    }
    $.ajax({
      type:'GET',
      url :"{:url('course/getS')}",
      data:'type_id='+type_id,
      dataType:'json',
      success : function(data){
        $.each(data.s_data, function(k,v){
          $('.sCopy').append('<option value="'+v.s_id+'">'+v.s_name+'</option>');
        });
      }
    });
  });
//批量移动
function changecate(o){
  var Checkbox=false;
   $("input[name='t_id[]']").each(function(){
    if (this.checked==true) {   
    Checkbox=true;  
    }
  });
  var sCopyId = $(".sCopy").val();
  if(sCopyId == 0)return false;
  if (Checkbox){    
    $('input[name=status]').val('copy');
    $("#listform").submit();    
  }
  else{
    alert("请选择要操作的内容!");
    
    return false;
  }
}
//搜索
function changesearch(){  
    $('input[name=status]').val('select');
    $("#listform").submit();
}

function changeNav(){
    $('input[name=status]').val('select');
    $("#listform").submit();
}


//全选
$("#checkall").click(function(){ 
  $("input[name='t_id[]']").each(function(){
    if (this.checked) {
      this.checked = false;
    }
    else {
      this.checked = true;
    }
  });
})

//批量删除
function DelSelect(){
  var Checkbox=false;
   $("input[name='t_id[]']").each(function(){
    if (this.checked==true) {   
    Checkbox=true;  
    }
  });
  if (Checkbox){
    var t=confirm("您确认要删除选中的内容吗？");
    if (t==false) return false;   
    $('input[name=status]').val('del');
    $("#listform").submit();    
  }
  else{
    alert("请选择您要删除的内容!");
    return false;
  }
}

//批量排序
function sorts(){
  var Checkbox=false;
   $("input[name='t_id[]']").each(function(){
    if (this.checked==true) {   
    Checkbox=true;  
    }
  });
  if (Checkbox){  
    $('input[name=status]').val('sort');
    $("#listform").submit();    
  }
  else{
    alert("请选择要操作的内容!");
    return false;
  }
}
//批量移动
function changecate(o){
  var Checkbox=false;
   $("input[name='t_id[]']").each(function(){
    if (this.checked==true) {   
    Checkbox=true;  
    }
  });
  if (Checkbox){    
    $('input[name=status]').val('move');
    $("#listform").submit();    
  }
  else{
    alert("请选择要操作的内容!");
    
    return false;
  }
}
$('#nav').change(function(){
    var nav_id = $(this).val();
    //$('#city')[0].options.length = 0;
    $("#type option:gt(0)").remove();
    $("#s option:gt(0)").remove();
    if(nav_id == ''){
      return;
    }
    $.ajax({
      type:'GET',
      url :"{:url('course/getType')}",
      data:'nav_id='+nav_id,
      dataType:'json',
      success : function(data){
        $.each(data, function(k,v){
          $('#type').append('<option value="'+v.type_id+'">'+v.type_name+'</option>');
        });
      }
    });
  });
$('#type').change(function(){
    var type_id = $(this).val();
    //$('#city')[0].options.length = 0;
    $("#s option:gt(0)").remove();
    if(type_id == ''){
      return;
    }
    $.ajax({
      type:'GET',
      url :"{:url('course/getS')}",
      data:'type_id='+type_id,
      dataType:'json',
      success : function(data){
        $.each(data, function(k,v){
          $('#s').append('<option value="'+v.s_id+'">'+v.s_name+'</option>');
        });
      }
    });
  });
</script>
</body>
</html>